package com.baizhi.service.impl;

import com.baizhi.dao.CmfzArticleDao;
import com.baizhi.entity.CmfzArticle;
import com.baizhi.service.CmfzArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 19:17
 * @Description:
 */
@Service
@Transactional
public class CmfzArticleServiceImpl implements CmfzArticleService {

    @Autowired
    private CmfzArticleDao articleDao;

    @Override
    public Map selectArticle(int rows, int page) {
        Map map=new HashMap();
        int start=(page-1)*rows+1;
        int pagesize=rows;
        List<CmfzArticle> list=articleDao.selectArticle(start,pagesize);
        int count=articleDao.selectCount();
        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public void update(CmfzArticle article) {
        articleDao.updateArticle(article);
    }

    @Override
    public void deleteMany(int[] ids) {
        for (int id:ids) {
            articleDao.delete(id);
        }

    }

    @Override
    public void addArticle(CmfzArticle article) {
        articleDao.insert(article);
    }

    @Override
    public List<CmfzArticle> selectAppGuru(int userId) {
        return articleDao.selectAppGuru(userId);
    }

    @Override
    public CmfzArticle selectIdGuruWithArticle(int articleId) {
        return articleDao.selectIdGuruWithArticle(articleId);
    }

    @Override
    public List<CmfzArticle> selectAppGuruAll(int userId) {
        return articleDao.selectAppGuruAll(userId);
    }
}
